/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.random;

/**
 * Class <code>RandomGeneratorFactory</code> 随机数生成器工厂.
 * 
 * @author jrwz
 * @version 2012-7-13下午04:16:54
 * @see com.lineage.server.random
 * @since JDK1.7
 */
public final class RandomGeneratorFactory {
    /** 实例. */
    private static RandomGenerator rnd = null;

    /**
     * 返回一个共享的随机数生成器.
     * 推荐使用 生产少量随机数。
     * 此方法返回的随机数生成器是安全执行绪(线程安全)外部同步不可用。
     * 不过，如果你有大量从多个线程在同一时间产生一个随机数的表现是依赖于随机数发生器的执行情况。
     * 
     * @return 共享的随机数生成器
     */
    public static RandomGenerator getSharedRandom() {
        if (rnd == null) {
            rnd = newRandom();
        }
        return rnd;
    }

    /**
     * 返回一个新的随机数发生器.
     * 此方法返回的随机数发生器是线程安全的
     * 
     * @return 新的随机数发生器
     */
    public static RandomGenerator newRandom() {
        return new StandardRandom();
    }

    /** 随机数生成器工厂. */
    private RandomGeneratorFactory() {
    }
}
